<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue2.js"></script>
</head>
<body>
    <div id="app">
        <father></father>
    </div>
    <template id="father">
        <div class="father">
            <p>我是父组件 叫做{{fname}}</p>
            <input type="button" value="点击告诉我儿子" @click="tellname">
            <son></son>
        </div>
    </template>
    <template id="son">
        <div class="son">
                <p>我是子组件 叫做{{sname}}</p>
                <h3>今天我父亲告诉我 我竟然是{{telled}}</h3>
        </div>
    </template>
</body>
<script>
    // 创建事件总线实例对象
    var bus = new Vue()
    // 父组件
    Vue.component('father',{
        template:"#father",
        data(){
            return{
                fname:"张三丰",
                tell:"富二代"
            }
        },
        methods: {
            tellname(){
                bus.$emit('getname',this.tell)
            }

        },
        // 子组件
        components: {
            'son':{
                template:"#son",
                data(){
                    return {
                        sname:"张夏明",
                        telled:''
                    }
                },
                mounted () {
                    bus.$on('getname',(data)=>{
                        this.telled=data;
                    })
                }
            }
        }

    })
    var vm = new Vue({
        el:"#app",
        data:{

        }
    })
</script>
</html>